<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8" isELIgnored="false"%>
<%@ include file="/WEB-INF/views/shared/taglib.jsp"%>

<div class="row">
	<div class="col-md-6 col-sm-6 col-lg-6 hidden-xs" >
		<c:set value="${studentSearch.searchItemList}" var="searchItemList" />
		<%@ include file="/WEB-INF/views/shared/master/searchItem.jsp"%>
	</div>
	<div class="col-md-6 col-sm-6 col-lg-6 col-xs-12 text-right">
		<t:roleButton />
	</div>
</div>

<div class="context-menu folder-context-menu">
	<ul class="dropdown-menu">
		<li><a data-action='share' href="#">共享</a></li>
		<li><a data-action='rename' href="#">重命名</a></li>
		<li><a data-action='delete' href="#">删除</a></li>
	</ul>
</div>
<div class="context-menu file-context-menu">
	<ul class="dropdown-menu">
		<li><a data-action='share' href="#">共享</a></li>
		<li><a data-action='rename' href="#">重命名</a></li>
		<li><a data-action='delete' href="#">删除</a></li>
		<li><a data-action='qrcode' href="#">二维码</a></li>
	</ul>
</div>
<script type="text/javascript">
	
	function upload(){
		var parentId=$("#parentId").val();
		var parentLevel=$("#parentLevel").val();
		top.ossChooseFile(parentId,parentLevel);
	}
	
	function uploadCallback(){
		loadOutput();
	}
	
	function loadOutput(){
		var reportType=$("#reportTypeSearch").val();
		var url=$.getVirtualPath()+"/admin/document/reportCataLog/output?reportType="+reportType;

		
		var outputHtml=$.getTextPost(url);
		//$("#searchKey").val("");
		$("#tableContent").html(outputHtml);
		
		redrawTable();

		bindOutputClick();
	}

	function bindOutputClick(){
		$(".file-container").on("click",function(){
			if($(this).hasClass("bg-primary")){
				$(this).removeClass("bg-primary");
			}else{
				$(".file-container.bg-primary").removeClass("bg-primary");
				$(this).addClass("bg-primary");
			}
		});
	}

	
	function leftMenuClick(reportType){
		$("#reportTypeSearch").val(reportType)
		loadOutput();
	}
	
	

function fileMenuInit(){
	$(".file-container").contextmenu({
		target:".file-context-menu",
		onItem:function(context,e){
			fileId=$(context).attr("data-id");
			var action = $(e.target).attr("data-action");
			switch(action){
				case "delete":
					confirm("确认删除该文件？",function(result){
						if(!result){
							return;
						}
						var url=$.getVirtualPath()+"/admin/file/fileCatalog/delete?key="+fileId;
						var result =$.getJsonPost(url);
						if(result.resultType = 'success'){
							loadOutput();
						}
					})
					break;
				case "share":
					openShare();
					break;
				case "qrcode":
					var showName=$(context).attr("data-showName");
					openQRCode(showName,fileId);
					break;
				case "unshare":
					var url=$.getVirtualPath()+"/admin/file/fileCatalog/unshare?key="+fileId;
					var result =$.getJsonPost(url);
					if(result.resultType=="success"){
						loadOutput();
					}
					break;
				case "rename":
					var showName = $(context).attr("data-showName");
					var ext = showName.substring(showName.indexOf("."),showName.length);
					showName = showName.substring(0,showName.indexOf("."));
					prompt("重命名文件",showName,function(newName){
						if($.isNull(newName)){
							return;
						}
						var url=$.getVirtualPath()+"/admin/file/fileCatalog/rename";
						var data="key="+fileId+"&newName="+newName+ext;
						
						var result=$.getJsonPost(url,data);
						if(result.resultType=="success"){
							loadOutput();
						}
					});
					break;
				case "revert":
					var url=$.getVirtualPath()+"/admin/file/fileCatalog/revert?key="+fileId;
					var result =$.getJsonPost(url);
					if(result.resultType=="success"){
						loadOutput();
					}
					break;
					
			}
		}
	});
	
}

function openShare(){
	top.openModal("/admin//superbase/role/roleEmployeeSelect/index","roleEmployeeSelect_form","分享至...",700,528);
}

function selectRoleEmployeeCallBack(roleSelected,employeeSelected){
	var url=$.getVirtualPath()+"/admin/file/fileCatalog/share";
	var result =$.getTextPost(url,"key="+fileId+"&roles="+roleSelected+"&employees="+employeeSelected);
	if(result.resultType = 'success'){
		$.topNotify("分享成功","success",1000);
		loadOutput();
	}
}

function openQRCode(showName,fileId){
	var url=$.getVirtualPath()+"/admin/file/fileCatalog/qrCode?fileId="+fileId;
	top.swal({
		title:showName,
        text: "<img style='width:300px;height:300px;' src='"+url+"' />",
        html: true,
        confirmButtonText : "确定",
        confirmButtonColor: "#2196F3"
    });
}
	

function addData(){
	top.openModal("/admin/document/reportCataLog/reportCataLogDetailed","reportCataLog_form","文件详情-添加",840,543);
	
}
function editData(){
	var id=getKeyId();
	if(isEditor(id)){
		top.openModal("/admin/document/reportCataLog/reportCataLogDetailed?key="+id,"reportCataLog_form","文件详情-修改",840,543);
	}
	
}
function selData(){
	var id=getKeyId();
	if(isEditor(id)){
		top.openModal("/admin/document/reportCataLog/reportCataLogDetailed?key="+id+"&mode=3","reportCataLog_form","文件详情-查看",840,543);	
	}
	
}
function deleteData(){
	var id=getKeyId();
	if(isEditor(id)){
		var url=$.getVirtualPath()+"/admin/document/reportCataLog/delete?key="+id;
		deleteDataEx(url,function(data){
			if(data.resultType=="success"){
				formSubmit();
			
			}
		});
	}
}	


</script>
